package com.nearby.demand.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.nearby.demand.R;
import com.nearby.demand.adapter.TimeLineAdapter;
import com.nearby.demand.db.Demand;

import java.util.ArrayList;
import java.util.List;


public class Fragmentsanz extends BaseFragment {
    private Activity ctx;
    private View layout;


    @Override
    protected void lazyLoad() {


    }

    @Override
    protected void onInvisible() {
        super.onInvisible();
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    protected void onVisible() {
        super.onVisible();
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
    }




    RecyclerView recycler_view;

    TimeLineAdapter timeLineAdapter;

    public void initDemands() {
        demands = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Demand demand = new Demand();
            demand.setPosition(i);
            demands.add(demand);
        }

    }

    List<Demand> demands;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (layout == null) {
            ctx = this.getActivity();
            layout = ctx.getLayoutInflater().inflate(R.layout.sand,
                    null);
            initDemands();
            recycler_view = (RecyclerView) layout.findViewById(R.id.recycler_view);
            recycler_view.setHasFixedSize(true);//固定尺寸
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
            timeLineAdapter = new TimeLineAdapter(demands);
            recycler_view.setLayoutManager(linearLayoutManager);
//                        recycler_view.addItemDecoration(new DividerItemDecoration(getActivity(),
//                                DividerItemDecoration.VERTICAL_LIST));
            recycler_view.setAdapter(timeLineAdapter);

        } else {
            ViewGroup parent = (ViewGroup) layout.getParent();
            if (parent != null) {
                parent.removeView(layout);
            }
        }
        return layout;
    }


}
